package com.pingao.mp.modular.sys.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author 闻品高
 * @since 2018-09-26
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ToString
@TableName("sys_user")
public class User extends Model<User> {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.ID_WORKER)
    //JsonSerialize解决数据传递到前端的时候其精度会丢失的问题，在序列化的时候把其序列化成字符串类型
    @JsonSerialize(using = ToStringSerializer.class)
    //ID_WORKER，采用mybatis-plus提供的雪花算法自动生成主键值
    private Long id;

    /**
     * 名称
     */
    private String name;

    /**
     * 密码
     */
    private String password;

    /**
     * 昵称
     */
    private String nick;

    /**
     * 电子邮件
     */
    private String email;

    /**
     * 性别（1，男、2，女）
     */
    private Integer gender;

    /**
     * 性别
     */
    @TableField(exist = false)
    private String genderName;

    /**
     * 生日
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime birthday;

    /**
     * 地址
     */
    private String address;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 删除时间
     */
    private LocalDateTime deleteTime;

    /**
     * 用户所属角色
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long roleId;

    /**
     * 头像
     */
    private String avatar;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    /**
     * 权限名称
     */
    @TableField(exist = false)
    private String roleName;

    //字段名称 仅供mybatis plus（条件构造）使用
    public static final String COL_ID = "id";
    public static final String COL_ID_JOIN = "u.id";

    public static final String COL_NAME = "name";
    public static final String COL_NAME_JOIN = "u.name";

    public static final String COL_PASSWORD = "password";
    public static final String COL_PASSWORD_JOIN = "u.password";

    public static final String COL_NICK = "nick";
    public static final String COL_NICK_JOIN = "u.nick";

    public static final String COL_EMAIL = "email";
    public static final String COL_EMAIL_JOIN = "u.email";

    public static final String COL_GENDER = "gender";
    public static final String COL_GENDER_JOIN = "u.gender";

    public static final String COL_BIRTHDAY = "birthday";
    public static final String COL_BIRTHDAY_JOIN = "u.birthday";

    public static final String COL_ADDRESS = "address";
    public static final String COL_ADDRESS_JOIN = "u.address";

    public static final String COL_CREATE_TIME = "create_time";
    public static final String COL_CREATE_TIME_JOIN = "u.create_time";

    public static final String COL_UPDATE_TIME = "update_time";
    public static final String COL_UPDATE_TIME_JOIN = "u.update_time";

    public static final String COL_DELETE_TIME = "delete_time";
    public static final String COL_DELETE_TIME_JOIN = "u.delete_time";

    public static final String COL_ROLE_ID = "role_id";
    public static final String COL_ROLE_ID_JOIN = "u.role_id";

    public static final String COL_AVATAR = "avatar";
    public static final String COL_AVATAR_JOIN = "u.avatar";

    public static final String COL_ROLE_NAME = "role.name";
    public static final String COL_ROLE_NAME_ALIAS = "role.name as role_name";//查询单个的时候用
}
